package com.example.mydemo103;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Wellcome extends AppCompatActivity {
    private TextView tiaozhuan;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wellcome);
        tiaozhuan=findViewById(R.id.tiaozhuan);
        begin();


        //    去除标题栏
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }

//        接受intent传输过来的Extra值
//        int id = getIntent().getIntExtra("id", 0);
//        if (id == 1) {
//            getSupportFragmentManager()
//                    .beginTransaction()
//                    .replace(R.id.navigation_home,new personFrgment())
//                    .addToBackStack(null)
//                    .commit();
//        }
    }
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                    tiaozhuan.setText(String.valueOf(msg.arg1)+"秒后跳转");
                    break;
            }
        }
    };
    public void begin(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i=3;i>0;i--){
                    Message msg = new Message();
                    msg.what = 1;
                    msg.arg1 = i;
                    handler.sendMessage(msg);
                    try {
                        Thread.sleep(1000);//休眠1秒
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //计时结束后跳转到其他界面
                startActivity(new Intent(Wellcome.this,LgoinActivity.class));
                //添加finish方法在任务栈中销毁倒计时界面，使新开界面在回退时直接退出而不是再次返回该界面
            }
        }).start();
    }
    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}
